﻿using System;
using System.Collections.Generic;

namespace Unity.Commons.Exceptions
{
    public static class ExceptionMessage
    {
        private static readonly Dictionary<ErrorCode, string> Messages 
            = new Dictionary<ErrorCode, string>();

        public static string ByCode(ErrorCode code)
        {
            if(Messages.Count > 0)
            {
                return Messages[code];
            } 
            else
            {
                return "No found exception message";
            }
        }

        static ExceptionMessage()
        {
            Messages.Add(ErrorCode.ValidationError, "Validation error");
            Messages.Add(ErrorCode.PayloadTooLarge, "Payload too large");
            Messages.Add(ErrorCode.ServerError, "Server error");
            Messages.Add(ErrorCode.HttpConnectException, "HTTP Connect Exception");
            Messages.Add(ErrorCode.HttpTimeoutException, "HTTP Timeout Exception");
            Messages.Add(ErrorCode.InternalHttpException, "HTTP Internal Exception");
            Messages.Add(ErrorCode.InternalRestClientError, "Internal REST client error");
            Messages.Add(ErrorCode.NoResponseFromServer, "No response from server");
            Messages.Add(ErrorCode.NoFoundResponseHandler, "No found response handler");
            Messages.Add(ErrorCode.SolaceError, "Error communication with Solace");
            Messages.Add(ErrorCode.SolaceConnection, "Error on connection to Solace");
            Messages.Add(ErrorCode.KafkaError, "Error communication with Kafka");
            Messages.Add(ErrorCode.KafkaConfigurationError, "Kafka configuration error");
            Messages.Add(ErrorCode.General, "General error");
            Messages.Add(ErrorCode.Internal, "Internal error");
            Messages.Add(ErrorCode.DuplicationCheckError, "Error in check duplication");
            Messages.Add(ErrorCode.Configuration, "Configuration error");
            Messages.Add(ErrorCode.ConfigurationBadKeystore, "Bad keystore in configuration");
            Messages.Add(ErrorCode.Fingerprint, "Fingerprint compose error");
            Messages.Add(ErrorCode.MBean, "Register MBean error");
            Messages.Add(ErrorCode.Liveness, "Liveness error");
            Messages.Add(ErrorCode.Mail, "Mail error");
            Messages.Add(ErrorCode.NoImplementation, "No implementation error");
            Messages.Add(ErrorCode.IllegalArgument, "Illegal argument error");
            Messages.Add(ErrorCode.MongoDbError, "Error while interact with Mongo DB");
            Messages.Add(ErrorCode.MongoDbConfigurationError, "Mongo DB configuration error");
            Messages.Add(ErrorCode.EemsAuthorizationError, "Error while trying eems authorization");
            Messages.Add(ErrorCode.EemeConfigurationError, "EEMS configuration error");
            Messages.Add(ErrorCode.CitiFederationBadResponse, "Citi Federation return bad response");
            Messages.Add(ErrorCode.CitiFederationConfigurationError, "Citi Federation configuration error");
            Messages.Add(ErrorCode.CitiFederationError, "Erro while trying to call Citi Federation");
            Messages.Add(ErrorCode.TimeDrift, "Time drift is beyond possibility, will be discarded");
            Messages.Add(ErrorCode.BadTimeout, "time out is lover than 0");
            Messages.Add(ErrorCode.ForceOfflineWasCalled, "Force offline can be called only for testing");
            Messages.Add(ErrorCode.CanNotConnectToStreaming, "Can not connect to streaming mode");
            Messages.Add(ErrorCode.CanNotConnectToFallback, "Can not connect to fallback mode");
            Messages.Add(ErrorCode.CloseThreadResource, "Cannot stop resource thread");
            Messages.Add(ErrorCode.SingleThreadAsyncRun, "Can not run async action because previous action still not executed");
            Messages.Add(ErrorCode.RestoreConnectionFail, "Cannot restore connection to streaming/fallback mode");
            Messages.Add(ErrorCode.StreamBufferFull, "Streaming buffer is full");
            Messages.Add(ErrorCode.AllBufferFull, "All buffers is full");
            Messages.Add(ErrorCode.TimeReferenceConnectionError, "Can not connect to time reference topic");
            Messages.Add(ErrorCode.InvalidKeystore, "Provided keystore not valid for provided CSI ID");
            Messages.Add(ErrorCode.EemsCsiIdNotPermitted, "CSI ID not registerd (or disabled) in EEMS");
            Messages.Add(ErrorCode.ConnectingError, "Exception while attempting to connect");
            Messages.Add(ErrorCode.CloseError, "Error while trying to close client");
            Messages.Add(ErrorCode.CreateTopic, "Error while trying to create topic");
            Messages.Add(ErrorCode.DeleteTopic, "Error while trying to delete topic");
            Messages.Add(ErrorCode.SendMessage, "Error while trying to send message");
            Messages.Add(ErrorCode.RequiredEnvMissed, "Required environment variable is missed");
            Messages.Add(ErrorCode.Defaults, "Error get default value");
            Messages.Add(ErrorCode.SslContext, "Error creating ssl context");
            Messages.Add(ErrorCode.CleanupTopic, "Error while trying to clean up topics");
            Messages.Add(ErrorCode.SubscriberConnection, "Subscriber connection atempt failed");
            Messages.Add(ErrorCode.ClientInitializationError, "Error initialize client");
            Messages.Add(ErrorCode.ClientReadSignatureError, "Error read signature from file");
            Messages.Add(ErrorCode.ClientNotValidSignatureError, "Not valid buffer file signature");
            Messages.Add(ErrorCode.ClientReadMetadataError, "Error read metadata from file");
            Messages.Add(ErrorCode.ClientExistsFileOverwriteDataError, "Error make new buffer file because processing file " +
                "already exists and contains binary data with wrong signature");
            Messages.Add(ErrorCode.ClientExistsFileAccessError, "Error make new buffer file because file already exists and access to read file is failed");
            Messages.Add(ErrorCode.ClientCurrentBufferIsUsedError, "Error make new buffer file because current filepath already used as buffer");
            Messages.Add(ErrorCode.ClientMakeBufferFileError, "Error make new buffer file");
            Messages.Add(ErrorCode.ClientCopyBufferFileError, "Erro make backup file because current operation to copy current data is failed");
            Messages.Add(ErrorCode.ClientBackupBufferFileError, "Error backup buffer file");
            Messages.Add(ErrorCode.ClientVerifyFileContentError, "Error verify offline data");
            Messages.Add(ErrorCode.ClientNoMoreGenerated, "Attempt to get pre-generated id, while pool is empty");
            Messages.Add(ErrorCode.ConnectToTimeReference, "Can not connect to time reference");            
        }
    }
}
